<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006~2017 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 李邦琦 <1536549251@qq.com>
// +----------------------------------------------------------------------

namespace app\crm\model;
use think\Db;
use think\Model;
use think\Cache;

class Workflow extends Model
{
    /**
     * 获取工作流列表
     * @param str $where <查询条件>
     * @param int $page <页码>
     * @param int $limit <每页显示条数>
     * @return array <日报列表信息>
     */
    public function getWorkflowData($where,$page,$limit)
    {
        $count = Db::name('mob_workflow_app')->where($where)->count();
        // 查询状态为1的用户数据 并且每页显示10条数据
        $workflowList = Db::name('mob_workflow_app')->where($where)->limit(($page-1)*$limit,$limit)->order('addtime DESC')->select();
        $users = Cache::get('users');
        foreach ($workflowList as &$val) {
            switch ($val['type']) {
                case '1': $val['type'] = '请假'; break;
                case '2': $val['type'] = '外勤'; break;
                case '3': $val['type'] = '出差'; break;
                case '4': $val['type'] = '报销'; break;
            }

            switch ($val['status']) {
                case '0': $val['status'] = '办理中'; break;
                case '1': $val['status'] = '同意'; break;
                case '2': $val['status'] = '驳回'; break;
            }

            switch ($val['leavetype']) {
                case '1': $val['leavetype'] = '事假'; break;
                case '2': $val['leavetype'] = '病假'; break;
                case '3': $val['leavetype'] = '年假'; break;
                case '4': $val['leavetype'] = '婚假'; break;
                default : $val['leavetype'] = ''; break;
            }
            $val['cc'] = $users[$val['cc']]['cn_name'];
            $val['user'] = $users[$val['user']]['cn_name'];
        }
        $rowsList = count($workflowList) ? $workflowList : false;
        $arrData["code"] = 0;
        $arrData["msg"] = '';
        $arrData["count"] = $count;
        $arrData["data"] = $rowsList;
        return $arrData;
    }


}